############
#This file contains the code to generate 
#FIGURE 2
########################
#packages
library(foreign)
library(gdata) 

#Get estimates (produced by Tab3.do)
results <-  read.xls("Fig2Estimates.xlsx", sheet=1, header = TRUE)

#Plot
models <- c("District controls", "+ District fixed effects", "+ MP characteristics" )
models.a <- c("", "", "")
pdf("Fig2.pdf", width = 12, height=6)
par(mar=c(6.1,8.1,2.1,1.1), mfrow=c(1,2))
#Panel (a)
     plot(0,0,type="n", ylim=c(1,3), xlim=c(-0.2, 1), 
     yaxt="n", xlab="", ylab="", main = "(a) MP-voter congruence", axes=F)
   axis(1, cex.axis=1, tcl=-0.3)
axis(2, at=3:1, labels=models, las=1, cex.axis=1, tick=F, line=-1.5, cex.lab=1.2)
mtext("Effect of reform intensity (standardized)", 1, line = 3)
for(j in 1:3){
#abline(h=j, col = "lightgray", lty = "dotted")
lines(c(-0.2, 1), c(j,j), col = "lightgray", lty = "dotted", lwd=0.9)
}
for(i in seq(-0.2, 1, 0.2)){
abline(v=i, col = "lightgray", lty = "dotted", lwd=0.9)
}
abline(v=0, col="Black",lty=2, lwd=1)
points(results$estCong, 3:1, pch=19, cex=1.1)
segments(results$estCong - 1.96*results$seCong, 3:1,results$estCong + 1.96*results$seCong, 3:1, lwd=1.1)

#Panel (b)
par(mar=c(6.1, 2.1, 2.1,7.1))
plot(0,0,type="n", ylim=c(1,3), xlim=c(-1, 0.2), 
     yaxt="n", xlab="", ylab="", main = "(b) Parliamentary attendance", axes=F)
axis(1, cex.axis=1, tcl=-0.3)
axis(2, at=3:1, las=1, labels=models.a, cex.axis=1, tick=F, line=-1.5, cex.lab=1.2)
mtext("Effect of reform intensity (standardized)", 1, line = 3)
for(j in 1:3){
lines(c(-1, 0.2), c(j,j), col = "lightgray", lty = "dotted", lwd=0.9)
}
for(i in seq(-1, 0.2, 0.2)){
abline(v=i, col = "lightgray", lty = "dotted", lwd=0.9)
}
abline(v=0, col="Black",lty=2, lwd=1)
points(results$estAttend, 3:1, pch=19, cex=1.1)
segments(results$estAttend - 1.96*results$seAttend, 3:1,results$estAttend + 1.96*results$seAttend, 3:1, lwd=1.1)
dev.off()